package com.server.common.feign.config;

import feign.Response;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * 响应拦截
 * @author LXC
 * @date 2022/9/11 9:06
 */
@Component
public class FeignClientResponseInterceptor extends SpringDecoder {

    public FeignClientResponseInterceptor(ObjectFactory<HttpMessageConverters> messageConverters) {
        super(messageConverters);
    }

    @Override
    public Object decode(final Response response, Type type) throws IOException {
        //设置单独处理feign请求
        Object o = super.decode(response, type);
//        R<?> r = (R<?>) o;
//        if(R.SUCCESS != r.getCode()){
//            throw new BusinessException(r.getMsg());
//        }
        return o;
    }

}
